local opts = {
	time_format = "%_H:%M:%S",
	ass_position = "7",
	show_clock_binding = "Alt+c",
	toggle_clock_binding = "Alt+C"
}(require "mp.options").read_options(opts, "clock")

local clock = mp.create_osd_overlay("ass-events")

local function update_clock()
	local time = os.date(opts.time_format)
	clock.data="{osd-ass-cc/1}{\\a" .. opts.ass_position .. "  }" .. time
	clock:update()
end

local timer = mp.add_periodic_timer(0.1, update_clock)
timer:stop()

local function toggle_clock()
	if timer:is_enabled() then
		timer:stop()
		clock:remove()
	else
		timer:resume()
	end
end

local function remove_clock()
	clock:remove()
end

local function show_clock()
	update_clock()
	mp.add_timeout(2, remove_clock)
end


mp.add_key_binding(opts.show_clock_binding, "ShowClock", show_clock)
mp.add_key_binding(opts.toggle_clock_binding, "ToggleClock", toggle_clock)
